package com.pilipala.mapper;

import com.github.pagehelper.Page;
import com.pilipala.dto.SearchDTO;
import com.pilipala.dto.UserIdDTO;
import com.pilipala.dto.UserPrivateDTO;
import com.pilipala.entity.User;
import com.pilipala.vo.UserVO;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface UserMapper {

    /**
     * 根据email查找用户
     * @param email 邮箱
     * @return 查询到的用户
     */
    @Select("select * from user where email = #{email}")
    User getByEmail(String email);

    /**
     * 插入用户
     * @param user User
     * @return user的主键
     */
    Integer insert(User user);

    /**
     * 更新用户除密码以外的信息
     * @param user 用户信息
     */
    void update(User user);


    /**
     * 关于用户的搜索接口
     * @param searchDTO 包括页码、页大小、搜索关键字、排序类型
     * @return 返回分页后的用户
     */
    Page<Long> search(SearchDTO searchDTO);

    UserVO getUserByIdWithFollow(UserIdDTO userIdDTO);

    @Select("select * from user where id = #{id}")
    User getUserById(Long id);
    @Insert("insert into follows (follower_id,followed_id) values (#{userId},#{followedId})")
    void follow(UserIdDTO userIdDTO);

    @Select("select id from follows where follower_id = #{userId} and followed_id = #{followedId}")
    Long get(UserIdDTO userIdDTO);

    @Delete("delete from follows where id = #{followsId}")
    void unfollow(Long followsId);

    /**
     * 获取关注列表
     * @param followerId 关注人的Id
     * @return 获取到分页后的数据
     */
    @Select("select followed_id from follows where follower_id = #{followerId}")
    Page<Long> getFollowed(Long followerId);
}
